package com.td.erhome.wxapi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.td.erhome.utils.ConstUtils;
import com.td.erhome.utils.RxBus;
import com.td.erhome.utils.T;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends AppCompatActivity implements IWXAPIEventHandler {

    private IWXAPI mIWXAPI;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mIWXAPI = WXAPIFactory.createWXAPI(this, ConstUtils.APP_ID);
        mIWXAPI.handleIntent(getIntent(),this);
    }

    @Override
    public void onReq(BaseReq baseReq) {
    }
    @Override
    public void onResp(BaseResp baseResp) {

        if (baseResp.getType()== ConstantsAPI.COMMAND_PAY_BY_WX){
            switch (baseResp.errCode){
                case 0: //成功
                    T.showLong(this,"支付成功");
                    RxBus.getInstance().post(ConstUtils.FINISH_CON);
                    finish();
                    break;
                case -1:  //失败
                    T.showLong(this,"支付成功");
                    break;
                case -2:  //取消
                    break;
                default: //未知错误
                    break;

            }

    }
}

    }
